<!--
*
* Copyright 2015 HISP Tanzania
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* @since 2015
* @author Joseph Chingalo profschingalo@gmail.com>
*
*
-->
<ion-header>
  <ion-navbar [color]="(colorSettings$ |async).colorAttributes.main">
    <ion-title> <span [translate]="'Tracker capture'"></span> </ion-title>
  </ion-navbar>
</ion-header>

<ion-content>
  <ion-grid>
    <ion-row>
      <ion-col>
        <div class="item-card" color="font-color" padding-top padding-bottom ion-button clear full text-center
          text-capitalize (tap)="openOrganisationUnitTree()">
          <img class="side-menu-icon" [src]="icons.orgUnit" />&nbsp;&nbsp;
          <span *ngIf="!selectedOrgUnit || !selectedOrgUnit.name" [translate]="organisationUnitLabel"></span>
          <span *ngIf="selectedOrgUnit && selectedOrgUnit.name">
            {{ selectedOrgUnit.name }}</span>
        </div>
        <div class="item-card" color="font-color" padding-top padding-bottom ion-button clear full text-center
          text-capitalize (tap)="openProgramList()">
          <img class="side-menu-icon" [src]="icons.program" />&nbsp;&nbsp;
          <span *ngIf="!selectedProgram || !selectedProgram.name" [translate]="programLabel"></span>
          <span *ngIf="selectedProgram && selectedProgram.name">{{
            selectedProgram.name
            }}</span>
        </div>
        <div *ngIf="isFormReady">
          <div class="event-storage-status">
            <span>
              <b> <span [translate]="'Synced'"></span> </b> :
              {{ storageStatus.online }}
              <b> <span [translate]="'Not synced'"></span> </b> :
              {{ storageStatus.offline }}
              <span *ngIf="showTrackerConflictHandler" margin-left>&nbsp;&nbsp;
                <tracker-conflict-handler [trackerConflictHandler]="trackerConflictHandler"
                  (successTrackerConflictHandler)="onSuccessTrackerConflictHandling($event)" (successDiscovering)="onSuccessDiscoveringTrackerData($event)"></tracker-conflict-handler>
              </span>
            </span>
          </div>
          <div class="item-card" (click)="hideAndShowColumns()" color="font-color" padding-top padding-bottom
            ion-button clear text-center text-capitalize icon-start>
            <ion-icon name="ios-eye" color="icon-color"></ion-icon>
            <span [translate]="'Columns'"></span>
          </div>
          <div class="item-card" (click)="registerNewTrackedEntity()" color="font-color" padding-top padding-bottom
            ion-button clear text-center text-capitalize icon-start>
            <ion-icon name="add" color="icon-color"></ion-icon>
            <span [translate]="'Add'"></span>
          </div>
        </div>
      </ion-col>
    </ion-row>

    <div *ngIf="isFormReady">
      <div *ngIf="isLoading">
        <loading [loadingSize]="'large'" [loadingMessage]="loadingMessage"></loading>
      </div>
      <div *ngIf="!isLoading" class="over-flow-container">
        <ion-row>
          <ion-col>
            <div *ngIf="tableLayout">
              <table class="table table-bordered" width="100%">
                <thead *ngIf="tableLayout && tableLayout.headers">
                  <tr>
                    <th *ngFor="let header of tableLayout.headers">
                      {{ header }}
                    </th>
                  </tr>
                </thead>
                <tbody *ngIf="tableLayout.rows">
                  <tr [ngStyle]="{ 'background-color': '#F4F4F4' }" *ngFor="
                      let row of tableLayout.rows;
                      let currentIndex = index
                    "
                    (click)="openTrackedEntityDashboard(currentIndex)">
                    <td *ngFor="let data of row">{{ data }}</td>
                  </tr>
                  <tr *ngIf="tableLayout.rows.length == 0">
                    <td colspan="100%">
                      <span [translate]="'There no data at the moment'"></span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </ion-col>
        </ion-row>
      </div>
    </div>
  </ion-grid>
</ion-content>
